package com.lww.springcloudapi.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import javax.management.relation.Role;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;

@Data
@AllArgsConstructor
@EqualsAndHashCode(callSuper = false) //比较HashCode值
@NoArgsConstructor //无参构造
@Accessors(chain = true) //链式编程
@ApiModel(value = "Employee对象", description = "员工表")
@TableName("tab_employee")
public class TabEmployee implements UserDetails, Serializable {

    @ApiModelProperty(value = "员工id")
    @TableId(value = "id", type = IdType.ASSIGN_ID)
    private int id;

    @ApiModelProperty(value = "员工账号")
    @TableField(value = "account")
    private String account;

    @ApiModelProperty(value = "员工密码")
    @TableField(value = "password")
    private String password;

    @ApiModelProperty(value = "员工权限")
    @TableField(value = "jurisdiction")
    private String jurisdiction;

    @ApiModelProperty(value = "员工名称")
    @TableField(value = "ename")
    private String ename;

    @ApiModelProperty(value = "员工所属营业厅")
    @TableField(value = "acptsiteid")
    private String acptsiteid;

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return Stream.of(jurisdiction.split(",")).map(SimpleGrantedAuthority::new).collect(Collectors.toList());
    }

    @Override
    public String getUsername() {
        return null;
    }

    @Override
    public boolean isAccountNonExpired() {
        return false;
    }

    @Override
    public boolean isAccountNonLocked() {
        return false;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return false;
    }

    @Override
    public boolean isEnabled() {
        return false;
    }
}